<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
  <title>前后端交互示例</title>
  <script>
    window.onload = function () {
      const btn = document.getElementById('btn')
      btn.addEventListener('click', () => {
        // sql 语句
        const sql = {
          select: "select * from user" // select: "insert into user (id,name) values (2,'张三1')"
        }
        new Promise(function (resolve) {
          $.post('/data',sql,data => {
            if (data !== '0') {
                const result = JSON.parse(data)[0];
                resolve(result);
                console.log(result)
            } else {
              console.log(data)
            }
          });
        })
      }) 
    }
  </script>
</head>
<body>
  <button id="btn">提交</button>
</body>
</html>